﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;
using FFS.IDAL;

namespace FFS.DALFactory
{
    /// <summary>
    /// 工厂类是不能被继承的封闭类，其中的函数全部设置为静态，通过类名可以直接访问其中的方法。
    /// </summary>
    public sealed class DataAccess
    {
        private static readonly string path = ConfigurationManager.AppSettings["DBDAL"];

        public static IFinanceItemDAO OperateFinanceItem()
        {
            string pathName = path + ".FinanceItemDAO";
            return (IFinanceItemDAO)Assembly.Load(path).CreateInstance(pathName);
            //Assembly.Load(要查找的程序集名称（即DLL名称）).CreateInstance(要查找的类名的完整名称（即在前面的程序集中查找该类名（命名空间+类名））);
        }

        public static ILoginUserDAO OperateLoginUser() 
        {
            string pathName = path + ".LoginUserDAO";
            return (ILoginUserDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static IFamilyMemberDAO OperateFamilyMember()
        {
            string pathName = path + ".FamilyMemberDAO";
            return (IFamilyMemberDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static ISysParameterDAO OperateSysParam()
        {
            string pathName = path + ".SysParameterDAO";
            return (ISysParameterDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static ISystemToolsDAO OperateSystemTools()
        {
            string pathName = path + ".SystemToolsDAO";
            return (ISystemToolsDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static ISystemLogDAO OperateSystemLog()
        {
            string pathName = path + ".SystemLogDAO";
            return (ISystemLogDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static ISysRemindDAO OperateSysRemind()
        {
            string pathName = path + ".SysRemindDAO";
            return (ISysRemindDAO)Assembly.Load(path).CreateInstance(pathName);
        }

        public static IFinanceDetailDAO OperateFinanceDetail()
        {
            string pathName = path + ".FinanceDetailDAO";
            return (IFinanceDetailDAO)Assembly.Load(path).CreateInstance(pathName);
        }
    }
    
    
}
